<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=F6eTaN7pws2E23tdZL5BHPQeRWBXyLbW"></script>
<script src="<%=basePath%>js/jquery-1.11.3.min.js"></script>
<script type="text/javascript">
	$(function() {
		var ctx = "${pageContext.request.contextPath}";
		var geoc = new BMap.Geocoder();
		var geolocation = new BMap.Geolocation();
		geolocation.getCurrentPosition(function(r) {
			if (this.getStatus() == BMAP_STATUS_SUCCESS) {
				var mk = new BMap.Marker(r.point);
				geoc.getLocation(r.point, function(rs) {
					var addComp = rs.addressComponents;
					var current_city = addComp.city;
					var street_info = addComp.district + addComp.street + addComp.streetNumber
					$.ajax({
				        type : "post",
				        url : ctx+"/index/location",
				        dataType:"json",
				        data: {
				        	l : current_city,
				        	lng : r.point.lng,
				        	lat : r.point.lat,
				        	street_info : street_info
				        },
				        success : function(msg) {
				        	window.location.href = ctx+"/index";
				        }
				    });
				});
			} else {
				alert('failed' + this.getStatus());
			}
		}, {
			enableHighAccuracy : true
		});
	});
</script>